<include file="Public:header"/>
<div class="managebox">
  <h3 class="title_m">账户设置</h3>
  <div class="managecontent clearfix">
    <div class="fl">
      <ul>
		<li><a href="{:get_url('account','','user')}">基本信息</a></li>
        <li class="cur"><a href="{:get_url('img','','user')}">修改头像</a></li>
        <li><a href="{:get_url('pwd','','user')}">修改密码</a></li>
        <li><a href="{:get_url('sns','','user')}">帐号绑定</a></li>
      </ul>
    </div>
    <div class="fr">
<form enctype="multipart/form-data" method="post" name="upform" target="upload_target" action="{:get_url('upload','','user')}">
<table cellpadding="0" cellspacing="0" width="100%">
		<tr>
          <td align="right" valign="top">上传新头像:</td>
          <td><input type="file" name="Filedata" id="Filedata"/>
			<input style="margin-right:20px;" type="submit" name="" value="上传形象照" onclick="return checkFile();" /><span style="visibility:hidden;" id="loading_gif"><img src="__PUBLIC__/statics/avatar/loading.gif" align="absmiddle" />上传中，请稍侯......</span><div class="note">建议使用正方形的图片，支持jpg、gif、png格式，2MB以内。</div></td>
        </tr>
        <tr>
          <td align="right" valign="top"></td>
          <td><div id="avatar_editor"><img width="150" onerror="this.src='__PUBLIC__/statics/images/avatar.png'" src="<present name='user_img'>{:C('web_path')}Uploads/avatar_big/{$user_img}<else />__PUBLIC__/statics/images/avatar.png</present>">
		  <img width="32" onerror="this.src='__PUBLIC__/statics/images/avatar-60.png'" src="<present name='user_img'>{:C('web_path')}Uploads/avatar_small/{$user_img}<else />__PUBLIC__/statics/images/avatar-60.png</present>">
		  </div></td>
        </tr>
       
		<!--<tr> 
          <td align="right" valign="top"></td>
         <td><input type="submit" class="btn_up" value="上传"/></td>
        </tr>-->
		 
      </table>
</form>
<iframe src="about:blank" name="upload_target" style="display:none;"></iframe>
    </div>
  </div>
</div>
<include file="Public:footer"/>
<script type="text/javascript">
		//允许上传的图片类型
		var extensions = 'jpg,jpeg,gif,png';
		//保存缩略图的地址.
		//var saveUrl = "__PUBLIC__/statics/avatar/save_avatar.php";
		//var saveUrl = "/index.php?a=saveAvatar&m=Uc&g=Home";//
		var saveUrl="{:C('web_path')}index.php?m=Uc%26a=saveAvatar%26g=Home";
		//保存摄象头白摄图片的地址.
		//头像编辑器flash的地址.
		var editorFlaPath = '__PUBLIC__/statics/avatar/AvatarEditor.swf';
		//Download by http://www.codefans.net
		function buildAvatarEditor(pic_id,pic_path,post_type)
		{
			var content = '<embed height="464" width="514"'; 
			content+='flashvars="type='+post_type;
			content+='&photoUrl='+pic_path;
			content+='&photoId='+pic_id;
			content+='&saveUrl='+saveUrl+'&radom=1"';
			content+=' pluginspage="http://www.macromedia.com/go/getflashplayer"';
			content+=' type="application/x-shockwave-flash"';
			content+=' allowscriptaccess="always" quality="high" src="'+editorFlaPath+'"/>';
			document.getElementById('avatar_editor').innerHTML = content;
		}
			/**
			 * 提供给FLASH的接口：编辑头像保存成功后的回调方法
			 */
			function avatarSaved(){
				//alert('保存成功，哈哈');
				window.location.href = "{:get_url('img','','user')}";

			}
			
			 /**
			  * 提供给FLASH的接口：编辑头像保存失败的回调方法, msg 是失败信息，可以不返回给用户, 仅作调试使用.
			  */
			 function avatarError(msg){
				 alert(msg);
				 alert("上传失败了呀，哈哈");
			 }

			 function checkFile()
			 {
				 var path = document.getElementById('Filedata').value;
				 var ext = getExt(path);
				 var re = new RegExp("(^|\\s|,)" + ext + "($|\\s|,)", "ig");
				  if(extensions != '' && (re.exec(extensions) == null || ext == '')) {
				 alert('对不起，只能上传jpg, gif, png类型的图片');
				 return false;
				 }
				 showLoading();
				 return true;
			 }

			 function getExt(path) {
				return path.lastIndexOf('.') == -1 ? '' : path.substr(path.lastIndexOf('.') + 1, path.length).toLowerCase();
			}
              function	showLoading()
			  {
				  document.getElementById('loading_gif').style.visibility = 'visible';
			  }
			  function hideLoading()
			  {
				document.getElementById('loading_gif').style.visibility = 'hidden';
			  }
		</script>